package cn.wyu.web;

import cn.wyu.pojo.User;
import cn.wyu.service.userSericeimpl;
import cn.wyu.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;

@WebServlet("/Register")
public class Register extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("注册新用户");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String  realName  = request.getParameter("realName");
        String addres = request.getParameter("addres");
        String phone = request.getParameter("phone");
        String sex = request.getParameter("sex");

        User user = new User();
        user.setLoginName(name);
        user.setPassword(password);
        user.setRealName(realName);
        user.setAddres(addres);
        user.setPhone(phone);
        if(sex=="man"){
            user.setSex(1);
        }else user.setSex(2);
        System.out.println(user);
        userService userservice = new userSericeimpl();
        Boolean aBoolean = userservice.adduser(user);

//        request.setAttribute("registermes","对不起，注册失败，请仔细检查");
//        request.getRequestDispatcher("register.jsp").forward(request,response);

        //返回数据给前端
        response.getWriter().print(aBoolean);
//        response.sendRedirect("login.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
